// pages/index/credit/index.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    options: {},
    page: {},
    height: 0,
    flag: true,
    rule:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })
      }
    })

    var _this = this;
    app.paiRequest("/app/customer/credit/details/findPage", { createBy: app.globalData.userInfo.id, pageNo: 1, pageSize: 10, item: 1 }).then(function (res) {
      console.log(res);
      var page = res.data;
      _this.setData({
        page: page
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onScrollLower:function(){
    var _this=this;
    var page=this.data.page;
    var list=page.list;
    var count=page.count;
    var lent=list.length;
    if (count == lent) {
      wx.showToast({
        title: '到底了',
        icon: 'success',
        duration: 1000
      })
    }else{
    app.paiRequest("/app/customer/credit/details/findPage", { createBy: app.globalData.userInfo.id, pageNo: page.pageNo + 1, pageSize: page.pageSize, item: 1 }).then(function (res) {      
      var currentPage = res.data;
      var pageList=list.concat(currentPage.list);
      page.list = pageList;
      page.pageNo = currentPage.pageNo;
      _this.setData({
        page: page
      })
    })
    }
  },
  showRule:function(){
    this.setData({
      flag:false
    })
    var _this=this;
    app.paiRequest("/app/customer/credit/rule/findList", { item: 1 }).then(function (res) {
      console.log(res);
      _this.setData({
        rule:res.data[0].text
      })
    })
  },
  // 遮罩层隐藏
  conceal: function () {
    this.setData({ flag: true })
  }
})